#!/usr/bin/env sh
# ******************************************************
# Filename     : seata-server-install-docker.sh
# Last modified: 2024-07-26 12:11
# Version      :
# Author       : jack.zang
# Email        : jack_zang@126.com
# Description  :
# source <(curl -sL https://gitee.com/jack_zang/public-scripts/raw/master/shell/seata-server/seata-server-install-docker.sh)
#
# ******************************************************

read -t 20 -p "请输入要安装的 seata-server 版本, 1.4.2、2.0.0 ,直接回车安装默认版本 2.0.0 " SEATA_V
read -t 20 -p "请输入服务器IP, 例: 192.168.10.220  " INSTALL_IP

[ -z "$INSTALL_IP" ] && echo "[ERROR] 未输入服务器IP,退出安装！" && exit 1
[ -z "$SEATA_V" ] && SEATA_V="2.0.0"

mkdir -pv /data/seata-server

case $SEATA_V in
  2.0.0)
    install_seata200
    ;;
  1.4.2)
    install_seata142
    ;;
  *)
    echo "[ERROR] seata-server 版本错误，退出安装"
    exit 1
esac        

function install_seata200() {
    curl -o /data/seata-server/application.yml https://gitee.com/jack_zang/public-scripts/raw/master/shell/seata-server/application.yml
    docker run --name seata-server -p 8091:8091 -p 7091:7091 -d --restart=always  \
        -e STORE_MODE=db  -e SEATA_IP=$INSTALL_IP -e SEATA_PORT=8091 \
        -v /data/seata200-server/application.yml:/seata-server/resources/application.yml  \
        seataio/seata-server:$SEATA_V
}

function install_seata142() {
    curl -o /data/seata-server/registry.conf \
        https://gitee.com/jack_zang/public-scripts/raw/master/shell/seata-server/registry.conf
    curl -o /data/seata-server/file.conf \
        https://gitee.com/jack_zang/public-scripts/raw/master/shell/seata-server/file.conf
    docker run --name seata-server -p 8091:8091 -d --restart=always \
        -e SEATA_CONFIG_NAME=file:/root/seata-config/registry \
        -e SEATA_IP=$INSTALL_IP -e SEATA_PORT=8091  -e  TZ=Asia/Shanghai \
        -v /data/seata-server:/root/seata-config \
        seataio/seata-server:$SEATA_V
}



